package com.shi.entity.dto;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

@Data
public class PageDto {
    private Integer pageNum=1;
    private Integer pageSize=10;
    private Boolean asc=true;
    private String orderBy;

    public <T> Page<T> toMPPage(Class<T> clazz){
        Page<T> page = Page.of(pageNum, pageSize);
        if (orderBy!=null){
            if (asc){
                page.addOrder(OrderItem.asc(orderBy));
            }else {
                page.addOrder(OrderItem.desc(orderBy));
            }
        }
        return page;
    }

    public <T> Page<T> toMPPageOrderByCreateTime(Class<T> clazz){
        Page<T> page = Page.of(pageNum, pageSize);
        page.addOrder(OrderItem.desc("create_time"));
        return page;
    }

    public <T> Page<T> toMPPage(Class<T> clazz,OrderItem... orderItems){
        Page<T> page = Page.of(pageNum, pageSize);
        page.addOrder(orderItems);
        return page;
    }
}
